<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>产品列表页</title>
<!-- 下载并引入jquery easyUI -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>
</head>
<body>
	<!-- 数据列表  start -->
	<!-- 在页面中使用easy ui组件进行界面编程 ,数据表格组件 -->
	<table id="classroom_dg" title="教室列表" class="easyui-datagrid"
		style="width: 1150px; height: 480px"
		url="${param.request.contextPath}/admin/classroomlist" toolbar="#classroom_toolbar"
		pagination="true" rownumbers="true" fitColumns="true"
		singleSelect="true">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<!--  field字段需要与返回数据的属性名一致 -->
				<th field="claroomId" align="center">教室编号</th>
				<th field="loc" width="50">教室地址</th>
			</tr>
		</thead>
	</table>
	<!-- 工具条组件 -->
	<div id="classroom_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newClassroom()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editClassroom()">修改</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyClassroom()">删除</a>
	</div>
	<!-- 数据列表 end  -->
	<!-- 新增和修改表单  start -->
	<div id="classroom_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#classroom_dlg-buttons">
		<div class="ftitle">商品信息管理</div>
		<form id="classroom_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>地址:</label> <input name="loc"
					class="easyui-validatebox" required="true">
			</div>
			
		</form>
	</div>
	<div id="classroom_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveClassroom()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#classroom_dlg').dialog('close')">取消</a>
	</div>
	<!-- 新增和修改表单 end -->
	<script type="text/javascript">
		//easy ui在处理多列数据时，需要使用格式化器解析数据
		function classroomFormatter(value, row, index) {
			//value是传递进来的classroom对象；row是当前行数据，index是第几行数据
			//return value.classroomName;
			return row.classroom.loc;
		}
		

		function newClassroom() {
			$('#classroom_dlg').dialog('open').dialog('setTitle', '新增教室信息');
			$('#classroom_fm').form('clear');
			url = '${pageContext.request.contextPath}/admin/classroomadd';
			loadClassroomSuccess(0);
		}
		function editClassroom() {
			$('#classroom_fm').form('clear');
			var row = $('#classroom_dg').datagrid('getSelected');
			if (row) {
				$('#classroom_dlg').dialog('open').dialog('setTitle', '修改教室信息');
				$('#classroom_fm').form('load', row);
				url = '${pageContext.request.contextPath}/admin/classroomedit?claroomId='
						+ row.claroomId;
				/* loadCategorySuccess(row.classroom.claroomId); */
			}
		}

		//下拉列表反选的方法
 	/* function loadCategorySuccess(classroom) {
			var data = $("#classroomCategory").combobox("getData");
			if (data && data.length > 0) {
				if (classroom == 0) {
					$("#classroomCategory")
							.combobox("setValue", data[0].claroomId);
				} else {
					$("#classroomCategory").combobox("setValue", classroom);
				}
			}
		}  */
		function saveClassroom() {
			$('#classroom_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							msg : result.errorMsg
						});
					}

					$('#classroom_dlg').dialog('close'); // close the dialog
					$('#classroom_dg').datagrid('reload'); // reload the user data
				}
			});
		}
		function destroyClassroom() {
			var row = $('#classroom_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除商品?',
								function(r) {
									if (r) {
										$
												.post(
														'${pageContext.request.contextPath}/admin/classroomdelete',
														{
															claroomId : row.claroomId
														},
														function(result) {
															if (result.success) {
																$('#classroom_dg')
																		.datagrid(
																				'reload'); // reload the user data
															} else {
																$.messager
																		.show({ // show error message
																			title : 'Error',
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			}
		}
		
	</script>
</body>
</html>